#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File    : tools.py
# @Time    : 2021/10/6 0:47
# @Author  : Karl·Marx
from jsonpath import jsonpath


class CommonTools:

    @staticmethod
    def json_path(obj_, expr):
        if obj_:
            try:
                values = jsonpath(obj_, expr)
                if values:
                    if len(values) == 1:
                        return values[0]
                    else:
                        return values
                else:
                    return None
            except Exception as e:
                return e
        else:
            return None
